import java.util.ArrayList;
import java.util.List;

public class Leet165 {
    public int compareVersion(String version1, String version2) {
        List<Integer> l1 = new ArrayList<>(),l2 = new ArrayList<>();
        int temp = 0;
        te(version1, l1, temp);
        temp = 0;
        te(version2, l2, temp);
        int m = Math.max(l1.size(),l2.size());
        for (int i = 0; i < m; i++) {
            if (i<l1.size()&&i<l2.size()){
                if(l1.get(i)>l2.get(i))
                    return 1;
                if(l1.get(i)<l2.get(i))
                    return -1;
            }
            if (i>=l1.size()&&l2.get(i)>0)
                return -1;
            if (i>=l2.size()&&l1.get(i)>0)
                return 1;
        }
        return 0;
    }
    private void te(String version1, List<Integer> l1, int temp) {
        for (int i = 0; i < version1.length(); i++)
            if (version1.charAt(i)=='.'){
                l1.add(Integer.parseInt(version1.substring(temp,i)));
                temp = i+1;
            }
        if (temp!=version1.length()&&Integer.parseInt(version1.substring(temp))!=0)
            l1.add(Integer.parseInt(version1.substring(temp)));
    }
}
